package com.taobao.top
{
	import com.taobao.top.resultmodel.*;
	
	import flash.events.Event;
	public class TOPTrade
	{
		public function TOPTrade()
		{
		}
		
		public function getTrades(fields:Array,iid:String,seller_nick:String,type:Array=[Trade_Type.GUARANTEE_TRADE,Trade_Type.AUTO_DELIVERY,Trade_Type.COD,Trade_Type.EC],page_no:int=1,page_size:int=40):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.trades.get"),
				new TopRequestParam("fields",TOPUtil.StringArrayToStringWidthComma(fields)),
				new TopRequestParam("iid",iid),
				new TopRequestParam("seller_nick",seller_nick),
				new TopRequestParam("type",TOPUtil.StringArrayToStringWidthComma(type))
				new TopRequestParam("page_no",page_no.toString()),
				new TopRequestParam("page_size",page_size.toString())
			)];
			topURLLdr.addEventListener(Event.COMPLETE,tradesGetHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		public function getTradesBought():void
		{
			
		}
		
		public function getTradesSold():void
		{
			
		}
		
		public function getTrade():void
		{
			
		}
		
		public function getTradeMemo():void
		{
			
		}
		
		public function updateTradeMemo():void
		{
			
		}
		
		public function closeTrade():void
		{
			
		}
		
		public function getTradeFullInfo():void
		{
			
		}
		
		private function tradesGetHandler(event:Event):void
		{
			switch(event.type)
			{
				case Event.COMPLETE:
					var trades:TradesGetResult = tradesGetJsonParser(event.target.data);
				break;
				default:
					 dispatchEvent(event.clone());
				break;
			}
		}
		
		private function tradesGetJsonParser(jsonStr:String):TradesGetResult
		{
			if(TOPError.isError(jsonStr))
			{
				var topError:TOPError = TOPError.parseError(jsonStr);
				//dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,
			}else
			{
				return objToTradesGetResult((JSON.decode(jsonStr) as Object).rsp);
			}
			return null;
		}
		
		private function objToTradesGetResult(obj:Object):objToTradesGetResult
		{
			//TODO: to be completed
		}
	}
}